package com.d3works.apps.hr.service;

import com.d3works.apps.hr.db.Employee;
import com.d3works.apps.hr.db.repo.ExpenseRepository;
import com.d3works.auth.db.User;
import com.d3works.meta.schema.actions.ActionView;

public class HRMenuValidateService {

  public void createValidateDomain(
      User user, Employee employee, ActionView.ActionViewBuilder actionView) {

    actionView
        .domain("self.statusSelect = :_statusSelect")
        .context("_statusSelect", ExpenseRepository.STATUS_CONFIRMED);

    if (employee == null || !employee.getHrManager()) {
      if (employee == null || employee.getManagerUser() == null) {
        actionView
            .domain(
                actionView.get().getDomain()
                    + " AND (self.employee.user.id = :_user_id OR self.employee.managerUser = :_user)")
            .context("_user_id", user.getId())
            .context("_user", user);
      } else {
        actionView
            .domain(actionView.get().getDomain() + " AND self.employee.managerUser = :_user")
            .context("_user", user);
      }
    }
  }
}
